//
//  BDDetailInfoTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/3/16.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDDetailInfoTableViewCell.h"

@interface BDDetailInfoTableViewCell ()

@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation BDDetailInfoTableViewCell

- (void)configeWithModel:(id)model{
    self.contentLabel.text = model;
    //    self.contentLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    self.contentLabel.top = 5;
    self.contentLabel.height = [self.contentLabel.text heightWithFont:[UIFont systemFontOfSize:14] width:kBDScreenWidth - 20];
}

+ (CGFloat)getCellHeightWithModel:(id)model{
    NSString *contntStr = model;
    return [contntStr heightWithFont:[UIFont systemFontOfSize:14] width:kBDScreenWidth - 20] + 10;
}

- (CGFloat)labelHeightWithText:(NSString *)text{
    NSString *tes = @"1\n2\n3";
    CGFloat hei = [tes heightWithFont:self.contentLabel.font width:self.contentLabel.width];
    
    CGFloat tureHeight = [[self contenTextWithText:text] heightWithFont:self.contentLabel.font width:self.contentLabel.width];
    
    return tureHeight > hei ? hei : tureHeight;
}

- (NSString *)contenTextWithText:(NSString *)text{
    BOOL needButton = [self getTextNumberWithText:text];
    if (needButton == YES) {
        int start = (kBDScreenWidth - 20) / 13 * 3;
        for (int i = start; i == 0; i--) {
            NSString *newStr = [[text substringToIndex:start] stringByAppendingString:ASLocalizedString(@"… 查看更多")];
            // BDLog(ASLocalizedString(@"新字符串：%@"), newStr);
            if ([self getTextNumberWithText:newStr] == NO) {
                return newStr;
            }
        }
        return [text stringByAppendingString:ASLocalizedString(@"显示全部")];
    }else{
        return text;
    }
}

- (BOOL)getTextNumberWithText:(NSString *)text{
    NSString *tes = @"1\n2\n3";
//    // BDLog(@"%@", tes);
    CGFloat hei = [tes heightWithFont:self.contentLabel.font width:self.contentLabel.width];
    
    CGFloat tureHeight = [text heightWithFont:self.contentLabel.font width:self.contentLabel.width];
    if (tureHeight > hei) {
        return YES;
    }else{
        return NO;
    }
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        self.contentLabel = [[UILabel alloc] init];
        _contentLabel.numberOfLines =0;
        _contentLabel.left = 10;
        _contentLabel.width = kBDScreenWidth - 20;
        _contentLabel.font = [UIFont systemFontOfSize:14];
//        _contentLabel.adjustsFontForContentSizeCategory = YES;
        [self addSubview:_contentLabel];
    }
    return _contentLabel;
}

@end
